package com.muki.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

import com.mongodb.MongoClient;
import com.muki.repository.BaseRepositoryImpl;

@Configuration
@ComponentScan({"com.muki"})
@EnableMongoRepositories(repositoryBaseClass=BaseRepositoryImpl.class,
basePackages="com.muki.repository")
public class MongoConfiguration {

	@Autowired private MongoDbProperties mongoDbProperties;
	
	@Bean
	public MongoDbFactory mongoDbFactory() throws Exception {
		return new SimpleMongoDbFactory(new MongoClient(mongoDbProperties.getHost()),mongoDbProperties.getDatabase());
	}
	
	@Bean
	public MongoTemplate mongoTemplate() throws Exception {
		MongoTemplate template = new MongoTemplate(mongoDbFactory());
		return template;
	}
}
